package com.xzc.seckill.controller;

import com.xzc.seckill.service.UserService;
import com.xzc.seckill.vo.LoginVo;
import com.xzc.seckill.vo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @author 徐生
 * @version 1.0
 * Date 2024/4/1 17:54
 * Description: LoginController
 */
@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    private UserService userService;

    //进入到登录也米娜
    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    //处理用户登录请求
    @PostMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Valid LoginVo loginVo, //@Valid：对该参数进行校验
                            HttpServletRequest request,
                            HttpServletResponse response){
        log.info("{}",loginVo);
        RespBean respBean = userService.doLogin(loginVo, request, response);
        return respBean;
    }
}
